package test_model_base;


import java.sql.Date;

import junit.framework.Assert;
import junit.framework.TestCase;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import com.servlet.model.base.Contact;

public class ContactTest extends TestCase {
	private Contact contact;
	private Date d1;
	private Date d2;
	@Before
	public void setUp() throws Exception {
		super.setUp();
		d1 = Date.valueOf("2012-01-01");
		d2 = Date.valueOf("2012-01-02");
		contact = new Contact("jialin.liu@u-psud.fr", "jingjing.li@u-psud.fr", true, d1, d2);
	}

	@After
	public void tearDown() throws Exception {
		contact = null;
		d1 = null;
		d2 = null;
	}

	@Test
	public void testContact() {
		contact = new Contact();
		Assert.assertEquals(false, contact.getIs_accepted());
		Assert.assertNull(contact.getEmail_user1());
		Assert.assertNull(contact.getEmail_user2());
		Assert.assertNull(contact.getDate_acceptation());
		Assert.assertNull(contact.getDate_invitation());
		Assert.assertEquals(false, contact.getIs_modified_accepted());
		Assert.assertEquals(false, contact.getIs_modified_date_acceptation());
		Assert.assertEquals(false, contact.getIs_modified_date_invitation());
	}

	@Test
	public void testContactStringStringBooleanDateDate() {
		contact = new Contact("jingjing.li@u-psud.fr", "jialin.liu@u-psud.fr", false, d2, null);
		Assert.assertEquals(false, contact.getIs_accepted());
		Assert.assertEquals(false, contact.getIs_modified_accepted());
		Assert.assertEquals(false, contact.getIs_modified_date_acceptation());
		Assert.assertEquals(false, contact.getIs_modified_date_invitation());
		Assert.assertEquals("jingjing.li@u-psud.fr", contact.getEmail_user1());
		Assert.assertEquals("jialin.liu@u-psud.fr", contact.getEmail_user2());
		Assert.assertEquals(d2, contact.getDate_invitation());
		Assert.assertNull(contact.getDate_acceptation());
	}

	@Test
	public void testGetEmail_user1() {
		Assert.assertEquals("jialin.liu@u-psud.fr", contact.getEmail_user1());
	}

	@Test
	public void testGetEmail_user2() {
		Assert.assertEquals("jingjing.li@u-psud.fr", contact.getEmail_user2());
	}

	@Test
	public void testGetIs_accepted() {
		Assert.assertEquals(true, contact.getIs_accepted());
	}

	@Test
	public void testGetDate_invitation() {
		Assert.assertEquals(d1, contact.getDate_invitation());
	}

	@Test
	public void testGetDate_acceptation() {
		Assert.assertEquals(d2, contact.getDate_acceptation());
	}

	@Test
	public void testGetIs_modified_accepted() {
		Assert.assertEquals(false, contact.getIs_modified_accepted());
	}

	@Test
	public void testGetIs_modified_date_acceptation() {
		Assert.assertEquals(false, contact.getIs_modified_date_acceptation());
	}

	@Test
	public void testGetIs_modified_date_invitation() {
		Assert.assertEquals(false, contact.getIs_modified_date_invitation());
	}

	@Test
	public void testSetIs_modified_accepted() {
		contact.setIs_accepted(false);
		Assert.assertEquals(true, contact.getIs_modified_accepted());
	}

	@Test
	public void testSetIs_modified_date_acceptation() {
		Date d = Date.valueOf("2012-02-01");
		contact.setDate_acceptation(d);
		Assert.assertEquals(true, contact.getIs_modified_date_acceptation());
	}

	@Test
	public void testSetIs_modified_date_invitation() {
		Date d = Date.valueOf("2010-01-01");
		contact.setDate_invitation(d);
		Assert.assertEquals(true, contact.getIs_modified_date_invitation());
	}

	@Test
	public void testSetEmail_user1() {
		contact.setEmail_user1("jialin.liu@gmail.com");
		Assert.assertEquals("jialin.liu@gmail.com", contact.getEmail_user1());
	}

	@Test
	public void testSetEmail_user2() {
		contact.setEmail_user2("jialin.liu@gmail.com");
		Assert.assertEquals("jialin.liu@gmail.com", contact.getEmail_user2());
	}

	@Test
	public void testSetIs_accepted() {
		contact.setIs_accepted(false);
		Assert.assertEquals(false, contact.getIs_accepted());
	}

	@Test
	public void testSetDate_invitation() {
		Date d = Date.valueOf("2010-01-01");
		contact.setDate_invitation(d);
		Assert.assertEquals(d, contact.getDate_invitation());
	}

	@Test
	public void testSetDate_acceptation() {
		Date d = Date.valueOf("2012-02-01");
		contact.setDate_acceptation(d);
		Assert.assertEquals(d, contact.getDate_acceptation());
	}

	@Test
	public void testGenerateInsertSQL() {
		Assert.assertEquals("INSERT INTO contact VALUES ('jialin.liu@u-psud.fr' ," +
				"'jingjing.li@u-psud.fr' ,true ,'2012-01-01', '2012-01-02')",
				contact.generateInsertSQL());
	}

	@Test
	public void testGenerateDeleteSQL() {
		Assert.assertEquals("DELETE FROM contact WHERE email_user_1='jialin.liu@u-psud.fr' AND email_user_2='jingjing.li@u-psud.fr'",
				contact.generateDeleteSQL());
	}

}
